<template>
	<view class="wrap">
		<u-form :model="model" :rules="rules" ref="uForm">
			<u-form-item label-width="350"
				:label-position="labelPosition" label="极限应力(MPa)" prop="limitStress">
				<u-input :border="border" placeholder="请输入极限应力" v-model="model.limitStress" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350"
				:label-position="labelPosition" label="安全系数" prop="safetyFactor">
				<u-input :border="border" placeholder="请输入安全系数" v-model="model.safetyFactor" type="digit"></u-input>
			</u-form-item>
		</u-form>

		<u-button type="primary" @click="submit">计算</u-button>

		<view class="u-config-wrap">
			<view class="u-config-item">
				<view class="u-item-title">计算结果</view>
				<u-form-item style="font-size: 22px;" :leftIconStyle="{color: '#888', fontSize: '32rpx'}" label-width="300"
					:label-position="labelPosition" label="许用应力" prop="allowableStress">
					<span v-if="model.allowableStress"> {{model.allowableStress}} MPa </span>
				</u-form-item>
				<u-form-item style="font-size: 22px;" :leftIconStyle="{color: '#888', fontSize: '32rpx'}" label-width="300"
					:label-position="labelPosition" label="许用切应力" prop="allowableShearStress">
					<span v-if="model.allowableShearStress"> {{model.allowableShearStress}} MPa </span>
				</u-form-item>
			</view>
			<view class="u-config-item">
				<view class="u-item-title">计算公式</view>
				<view class="u-item-desc">许用应力 [σ]=σs/ns</view>
				<view class="u-item-desc">其中，σs--构件失效的极限应力（塑性材料可以按抗拉强度计算）</view>
				<view class="u-item-desc">ns---脆性材料安全系数，脆性材料均匀性差，且断裂突然发生，有更大的危险性，所以取2.0-3.5，为方便计算取3.0</view>
				<view class="u-item-desc">许用切应力 = 许用应力 × 0.8</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				model: {
					limitStress: '',
					safetyFactor: '1.6',
					allowableStress: '',
					allowableShearStress: ''
				},
				rules: {
					limitStress: [{
						required: true,
						message: '请输入极限应力',
						trigger: 'blur'
					}],
					safetyFactor: [{
						required: true,
						message: '请输入安全系数',
						trigger: 'blur'
					}]
				},
				labelPosition: 'left',
				border: true,
				
			};
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			submit() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						// 计算许用应力
						this.model.allowableStress = (parseFloat(this.model.limitStress) / parseFloat(this.model.safetyFactor)).toFixed(2);
						// 计算许用切应力
						this.model.allowableShearStress = (parseFloat(this.model.allowableStress) * 0.8).toFixed(2);
					}
				});
			}
		}
	};
</script>

<style scoped lang="scss">
	.wrap {
		padding: 30rpx;
	}

	.u-config-wrap {
		margin-top: 30rpx;
	}

	.u-config-title {
		padding: 20rpx;
		font-size: 32rpx;
		font-weight: bold;
	}

	.u-config-item {
		padding: 20rpx;
	}

	.u-item-title {
		font-size: 28rpx;
		font-weight: bold;
		margin-bottom: 10rpx;
	}

	.u-item-desc {
		font-size: 24rpx;
		color: #666;
		margin-bottom: 5rpx;
	}
</style> 